package com.erdos.message.entity;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.erdos.common.entity.AbstractEntity;

public class MessageHandlerMapping extends AbstractEntity {
	private static final long serialVersionUID = -7330905175404765053L;

	/**
	 * associated MessageChannel
	 */
	private MessageChannel messageChannel;

	/**
	 * handler for the business domain object or ServiceInvocation, 
	 * full qualified name, that is, packageName.className
	 */
	private String handler;
	/**
	 * if the handler is a event processor, then this property indicates the event id
	 */
	private String eventId;
	
	private String entity;

	private boolean waived;

	private long channelSid;
	/**
	 * target application, the current running application only starts up the message listeners belongs to this application.
	 */
	private String targetApplication;
	
	private short waivedFlag;

	/**
	 * @return the channelSid
	 */
	public long getChannelSid() {
		return channelSid;
	}

	/**
	 * @param channelSid the channelSid to set
	 */
	public void setChannelSid(long channelSid) {
		this.channelSid = channelSid;
	}

	/**
	 * @return the messageChannel
	 */
	public MessageChannel getMessageChannel() {
		return messageChannel;
	}

	/**
	 * @param messageChannel the messageChannel to set
	 */
	public void setMessageChannel(MessageChannel messageChannel) {
		this.messageChannel = messageChannel;
	}

	/**
	 * @return the handler
	 */
	public String getHandler() {
		return handler;
	}

	/**
	 * @param handler the handler to set
	 */
	public void setHandler(String handler) {
		this.handler = handler;
	}

	/**
	 * @return the eventId
	 */
	public String getEventId() {
		return eventId;
	}

	/**
	 * @param eventId the eventId to set
	 */
	public void setEventId(String eventId) {
		this.eventId = eventId;
	}

	/**
	 * @return the entity
	 */
	public String getEntity() {
		return entity;
	}

	/**
	 * @param entity the entity to set
	 */
	public void setEntity(String entity) {
		this.entity = entity;
	}
	
	
	public String getTargetApplication() {
		return targetApplication;
	}

	public void setTargetApplication(String targetApplication) {
		this.targetApplication = targetApplication;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((handler == null) ? 0 : handler.hashCode());
		result = prime * result
				+ ((messageChannel == null) ? 0 : messageChannel.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof MessageHandlerMapping))
			return false;
		final MessageHandlerMapping other = (MessageHandlerMapping) obj;
		if (handler == null) {
			if (other.handler != null)
				return false;
		} else if (!handler.equals(other.handler))
			return false;
		if (messageChannel == null) {
			if (other.messageChannel != null)
				return false;
		} else if (!messageChannel.equals(other.messageChannel))
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return new ToStringBuilder(this).append(this.messageChannel).append(this.entity).append(
				this.handler).append(this.targetApplication).append(this.eventId).append(this.waived).toString();
	}

	/**
	 * @return the waivedFlag
	 */
	public short getWaivedFlag() {
		return waivedFlag;
	}

	/**
	 * @param waivedFlag the waivedFlag to set
	 */
	public void setWaivedFlag(short waivedFlag) {
		this.waivedFlag = waivedFlag;
	}

	/**
	 * @return the waived
	 */
	public boolean isWaived() {
		boolean flag = false;
		if(Short.valueOf("1").equals(this.getWaivedFlag())){
			flag = true;
		}
		return waived = flag;
	}

	/**
	 * @param waived the waived to set
	 */
	public void setWaived(boolean waived) {
		if(waived){
			this.setWaivedFlag(Short.valueOf("1"));
		}else{
			this.setWaivedFlag(Short.valueOf("0"));
		}
		this.waived = waived;
	}
}
